from django.test import TestCase
from dingxiang_doctor.utils.myredis import r
from elasticsearch import Elasticsearch

# Create your tests here.
# 修改es数据
# hospital_update_list = r.get_key(r"hospital:*")
# for i in hospital_update_list:
#     data = i.decode()
#     _index = data.find(":")
#     es_id = data[_index+1:]
#     info = r.hash_getall(data)
#     info = {key.decode(): value.decode() for key, value in info.items()}
#     es = Elasticsearch("http://121.40.61.16:9200")
#     es.update(index="dingxiang_doctor", id=es_id, body={
#         "doc": {
#             "id": info.get("id"),
#             "type": info.get("type"),
#             "name": info.get("name")
#         }
#     })

# 数据库删除数据，修改es
# es = Elasticsearch("http://121.40.61.16:9200")
# length = r.list_len("delete_list")
# for i in range(length):
#     data = r.list_lrange("delete_list", 0, 1)
#     for j in data:
#         es.delete(index="dingxiang_doctor", id=j.decode())
#     r.list_lpop("delete_list")
